#include "widget.h"

#include <QRadioButton>
#include <QVBoxLayout>
#include <QDebug>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
{
    resize(640, 480);

    QRadioButton *boy = new QRadioButton("男");
    QRadioButton *girl = new QRadioButton("女");
    QRadioButton *xx = new QRadioButton("未知");

    QVBoxLayout *layout = new QVBoxLayout;
    layout->addWidget(boy);
    layout->addWidget(girl);
    layout->addWidget(xx);
    setLayout(layout);

    //这个信号的含义是：当状态发生变更的时候，会被触发
    connect(boy, &QRadioButton::toggled, [=](bool flag){
        if(flag)
        {
            qDebug() << "男生被选中了";
        }
        else
        {
            qDebug() << "男生没有被选中了";
        }

        if(boy->isChecked())
        {
            qDebug() <<"也可以表明男生被选中了";
        }

    });

}

Widget::~Widget()
{
}

